using System;
using System.Collections;
using DataAccessLayer;
using System.Reflection;

namespace NorthwindDAO
{
	public class Invoice : Entity
	{
		private Int32 _ID_INVOICE;
		private String _CD_INVOICE;
		private DateTime _DT_INVOICE;
		private Decimal _AM_INVOICE;
		private DateTime _DT_DUE;
		private String _NM_ENTERED_BY;
		private String _ID_BATCH;
		private String _DS_PERIOD;
		private Int32 _DT_YEAR;
		private Int32 _ID_VENDOR;
		private String _IN_HOLD;
		private String _IN_SINGLE_CHECK;
		private String _IN_PARTIAL_FINAL;
		private String _ID_CASH_ACCT;
		private Int32 _ID_ENCUMBRANCE;
		private String _CD_PAYMENT_TYPE;
		private String _IN_PROCESS;
	
		///Default constructor
		public Invoice ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available CHILD tables to join with:
		///    - Flowcontrol ( Flowcontrol_fk_flowcontrol_invoice )
		///    - Lineitems ( Lineitems_fk_lineitems_invoice )
        /// </summary>
        public Invoice(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_"; ;
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}
        public Invoice(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		[IsNotNullable]
		[IsPK]
		[IsIdentity]
		[SequenceNameAttribute("Invoice")]
		public Int32 Id_invoice
		{
			get
			{
				return _ID_INVOICE;
			}
		}
		[MaxLength(10)]
		public String Cd_invoice
		{
			get
			{
				return _CD_INVOICE;
			}
			set
			{
				_CD_INVOICE = value;
			}
		}
		[DefaultValue("(getdate())")]
		public DateTime Dt_invoice
		{
			get
			{
				return _DT_INVOICE;
			}
			set
			{
				_DT_INVOICE = value;
			}
		}
		public Decimal Am_invoice
		{
			get
			{
				return _AM_INVOICE;
			}
			set
			{
				_AM_INVOICE = value;
			}
		}
		public DateTime Dt_due
		{
			get
			{
				return _DT_DUE;
			}
			set
			{
				_DT_DUE = value;
			}
		}
		[MaxLength(10)]
		public String Nm_entered_by
		{
			get
			{
				return _NM_ENTERED_BY;
			}
			set
			{
				_NM_ENTERED_BY = value;
			}
		}
		[MaxLength(12)]
		public String Id_batch
		{
			get
			{
				return _ID_BATCH;
			}
			set
			{
				_ID_BATCH = value;
			}
		}
		[MaxLength(10)]
		public String Ds_period
		{
			get
			{
				return _DS_PERIOD;
			}
			set
			{
				_DS_PERIOD = value;
			}
		}
		public Int32 Dt_year
		{
			get
			{
				return _DT_YEAR;
			}
			set
			{
				_DT_YEAR = value;
			}
		}
		public Int32 Id_vendor
		{
			get
			{
				return _ID_VENDOR;
			}
			set
			{
				_ID_VENDOR = value;
			}
		}
		[MaxLength(10)]
		public String In_hold
		{
			get
			{
				return _IN_HOLD;
			}
			set
			{
				_IN_HOLD = value;
			}
		}
		[MaxLength(1)]
		public String In_single_check
		{
			get
			{
				return _IN_SINGLE_CHECK;
			}
			set
			{
				_IN_SINGLE_CHECK = value;
			}
		}
		[MaxLength(1)]
		public String In_partial_final
		{
			get
			{
				return _IN_PARTIAL_FINAL;
			}
			set
			{
				_IN_PARTIAL_FINAL = value;
			}
		}
		[MaxLength(10)]
		public String Id_cash_acct
		{
			get
			{
				return _ID_CASH_ACCT;
			}
			set
			{
				_ID_CASH_ACCT = value;
			}
		}
		public Int32 Id_encumbrance
		{
			get
			{
				return _ID_ENCUMBRANCE;
			}
			set
			{
				_ID_ENCUMBRANCE = value;
			}
		}
		[MaxLength(1)]
		public String Cd_payment_type
		{
			get
			{
				return _CD_PAYMENT_TYPE;
			}
			set
			{
				_CD_PAYMENT_TYPE = value;
			}
		}
		[DefaultValue("('N')")]
		[MaxLength(1)]
		public String In_process
		{
			get
			{
				return _IN_PROCESS;
			}
			set
			{
				_IN_PROCESS = value;
			}
		}
	
        #region Flowcontrol 
        private EntityCollection _Flowcontrol;
        [NotInTable]
        [TypeContainedAttribute(typeof(Flowcontrol),"Flowcontrol")]
        public EntityCollection Flowcontrol
        {
            get
            {
                return _Flowcontrol;
            }

            set
            {
                _Flowcontrol = value;
            }
        }
        private Flowcontrol _Flowcontrol_;
        [NotInTable]
        public Flowcontrol Flowcontrol_
        {
            get
            {
                return _Flowcontrol_;
            }

            set
            {
                _Flowcontrol_ = value;
            }
        }
        #endregion
	
        #region Lineitems 
        private EntityCollection _Lineitems;
        [NotInTable]
        [TypeContainedAttribute(typeof(Lineitems),"Lineitems")]
        public EntityCollection Lineitems
        {
            get
            {
                return _Lineitems;
            }

            set
            {
                _Lineitems = value;
            }
        }
        private Lineitems _Lineitems_;
        [NotInTable]
        public Lineitems Lineitems_
        {
            get
            {
                return _Lineitems_;
            }

            set
            {
                _Lineitems_ = value;
            }
        }
        #endregion
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "Flowcontrol", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Id_invoice");
				right.Add(GetType().Name + ".Id_invoice");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "Lineitems", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Id_invoice");
				right.Add(GetType().Name + ".Id_invoice");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			return null;
		}
	}
}


